home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
1833
/
1833.xpi
/
chrome
/
yoono.jar
/
ff3
/
bookmarks.js
< prev
Wrap
Text File
|
2009-12-16
|
5KB
|
162 lines
// lazy loaded (not ready at xpcom loading)
var BKMSERV=null;
var HISTSERV=null;
var LIVESERV=null;
function start(launch) {
BKMSERV=CL['@mozilla.org/browser/nav-bookmarks-service;1'].getService(CI.nsINavBookmarksService);
HISTSERV=CL['@mozilla.org/browser/nav-history-service;1'].getService(CI.nsINavHistoryService);
LIVESERV = CL["@mozilla.org/browser/livemark-service;2"].getService(CI.nsILivemarkService);
gCurrentTree = new bkmNode(BKMSERV.bookmarksMenuFolder, null, true);
gToolbarNode = new bkmNode(BKMSERV.toolbarFolder,gCurrentTree, true);
gCurrentTree.addChild(gToolbarNode);
BKMSERV.addObserver(BkmsObserver, false);
launch();
//yoono.bkm.dump();
}
function uri(uri) {
return Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService).newURI(uri, null, null);
}
var gBrowserBkm = {
runInBatchMode : function (process) {
BKMSERV.runInBatchMode({
runBatched : function () {
log.debug("START BATCH!");
process();
log.debug("END BATCH!");
}
}, null);
},
createBookmark : function ( title, url, parent) {
//log.debug(" create bookmark = title:"+title+" url:"+url+" parentId:"+parent.getId());
BKMSERV.insertBookmark(parent.getId(), uri(url), -1, title);
},
createLivemark : function ( title, url, parent) {
log.debug(" create livemark = title:"+title+" url:"+url+" parentId:"+parent.getId());
var nsurl=uri(url);
LIVESERV.createLivemark(parent.getId(),title,uri(nsurl.prePath),nsurl,-1);
},
create : function (node, parent) {
log.debug(" create from node = nodeId:"+node+" parentId:"+parent.getId());
if (node.isLive())
return this.createLivemark(node.getName(),node.getUrl(),node.getParent());
return this.createBookmark(node.getName(),node.getUrl(),node.getParent());
},
createFolder : function (name, parent) {
//log.debug(" create folder = title:"+name+" parentId:"+parent.getId());
var id = BKMSERV.createFolder(parent.getId(),name,-1);
return BkmsObserver.onItemAdded(id,parent.getId(),-1);
},
rename : function (node) {
log.debug(" rename nodeId:"+node.getId()+" title:"+node.getName());
BKMSERV.setItemTitle(node.getId(),node.getName());
},
remove : function (node) {
//log.debug(" remove bookmark nodeId:"+node.getId());
BKMSERV.removeItem(node.getId());
return BkmsObserver.onItemRemoved(node.getId(),node.getParent().getId(),-1);
}
}
function bkmNode(id, parent) {
this.id=id;
this.childsList=[];
this.private=false;
gBkmById[id] = this;
this.update(parent);
if (this.isFolder()) {
var options = HISTSERV.getNewQueryOptions();
var query = HISTSERV.getNewQuery();
query.setFolders([id], 1);
var result = HISTSERV.executeQuery(query, options);
var rootNode = result.root;
rootNode.containerOpen = true;
var cc = rootNode.childCount;
nbBkms --;
for (var i=0; i < cc; ++i) {
var node = rootNode.getChild(i);
if ( node.type != node.RESULT_TYPE_SEPARATOR ) { // ignore separator and "classeur/tags" folder
nbBkms ++;
this.childsList.push(new bkmNode(node.itemId, this));
}
}
}
}
// called on properties update
bkmNode.prototype.update = function (parent) {
var oldParent=this.parent, oldType=this.type, oldName=this.name, oldUrl=this.url;
this.parent=parent?parent:this.parent;
this.type=BKMSERV.getItemType(this.id);
// Replace toolbar folder name
if (this.id==BKMSERV.toolbarFolder)
this.name=TOOLBARNAME;
else
this.name = BKMSERV.getItemTitle(this.id);
// avoid void getName()!
if (!this.name)
this.name="";
try {
this.url=( this.isBookmark() ? BKMSERV.getBookmarkURI(this.id).spec : (this.isLive()?LIVESERV.getFeedURI(this.id).spec:null) );
} catch(e) {
log.error("Error, Corrupted bookmark, id: " + this.id + ", name: " + this.name);
}
this.path=false;
if (this.isBookmark() || this.isLive()) {
if (oldUrl)
delete gBkmByUrl[oldUrl];
gBkmByUrl[this.getUrl()] = this;
}
if (oldParent!=this.parent || (this.isFolder() && oldName!=this.name))
this.traverseNode({onNode:function(node){node.path=false}});
if (oldParent!=this.parent || oldType!=this.type || oldName!=this.name || oldUrl!=this.url) {
this.syncid=false;
this.path = false;
this.resetSyncid();
return true;
}
return false;
}
bkmNode.prototype.isFolder = function () {
return (this.type==BKMSERV.TYPE_FOLDER && !this.isLive());
}
bkmNode.prototype.isBookmark = function () {
return (this.type==BKMSERV.TYPE_BOOKMARK);
}
bkmNode.prototype.isLive = function () {
return LIVESERV.isLivemark(this.id);
}